package com.wswy.wzcx.model

import android.arch.lifecycle.MutableLiveData
import android.content.Intent
import android.os.Parcelable
import android.support.annotation.ColorRes
import android.support.v4.content.ContextCompat
import com.blankj.utilcode.util.SPUtils
import com.wswy.wzcx.AppContext
import com.wswy.wzcx.R
import com.wswy.wzcx.model.car.Inspection
import com.wswy.wzcx.model.car.InsuranceInfo
import com.wswy.wzcx.model.home.ExtHomeMapper
import com.wswy.wzcx.model.home.ExtModule
import com.wswy.wzcx.ui.Constants


fun List<ExtHomeMapper?>.convert():MutableMap<String,List<ExtModule>>{

    val data = LinkedHashMap<String, List<ExtModule>>()

    forEach {

        val list = it?.items?.toMutableList()

        list?.iterator()?.run {

            while (hasNext()){
                val module = next()

                //是否能显示
                if (module.canShow(AppContext.getContext())){

                    //修改了内容，导致无法equals，优化！
                    if (SPUtils.getInstance().getBoolean(module.spKey,false)){
                        //清除已点击过的tag
                        module.tag = null
                    }
                }else{
                    //不能显示  删除
                    remove()
                }
            }
        }

        if (list?.isNotEmpty() == true && it.title != null) {
            data[it.title] = list
        }
    }

    return data
}


data class RemainStatusColor(@ColorRes val numberColor:Int,@ColorRes val unitColor:Int)

private val statusColor = mapOf<Int,RemainStatusColor>(
        1 to RemainStatusColor(R.color.textColorPrimary,R.color.textColorPrimary_40),
        2 to RemainStatusColor(R.color.accentColor1,R.color.accentColor1),
        3 to RemainStatusColor(R.color.accentColor3,R.color.accentColor3)
)

fun Inspection.getStatusColor():RemainStatusColor{
    return statusColor.getOrElse(status){
        statusColor[1]!!
    }
}

fun InsuranceInfo.getStatusColor():RemainStatusColor{
    return statusColor.getOrElse(status){
        statusColor[1]!!
    }
}


inline fun <T> MutableLiveData<T>.reSend(){
    postValue(value)
}